package com.wannengbang.cloudleader.homepage.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.wannengbang.cloudleader.R;
import com.wannengbang.cloudleader.bean.SettlementRecordsBean;
import com.wannengbang.cloudleader.utils.NumberFormatUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Author: HWC
 * Description: 合伙人列表
 */
public class SettlementListAdapter extends RecyclerView.Adapter<SettlementListAdapter.ViewHolder> {


    private List<SettlementRecordsBean.DataBean.ItemListBean> listsBeans;
    private Context context;

    public SettlementListAdapter(List<SettlementRecordsBean.DataBean.ItemListBean> listsBeans) {
        this.listsBeans = listsBeans;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
        context = viewGroup.getContext();
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_settlement_list, viewGroup, false);
        ViewHolder viewHolder = new ViewHolder(inflate);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        SettlementRecordsBean.DataBean.ItemListBean dataBean = listsBeans.get(position);
        holder.tvNumber.setText("结算数量：" + dataBean.getNumber());
        String money = NumberFormatUtils.formatTwoDecimal(Double.parseDouble(dataBean.getMoney()) / 100);
        holder.tvMoney.setText("结算金额：" + money + "元");
        holder.tvDate.setText("结算日期：" + dataBean.getStart_date() + " 至 " + dataBean.getEnd_date());
    }

    @Override
    public int getItemCount() {
        return listsBeans.size() == 0 ? 0 : listsBeans.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_number)
        TextView tvNumber;
        @BindView(R.id.tv_money)
        TextView tvMoney;
        @BindView(R.id.tv_date)
        TextView tvDate;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
